﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace HideNSeek
{
	public partial class MainPage : UserControl
	{
        Random random = new Random();
        DispatcherTimer dispatcherTimer = new DispatcherTimer();

		public MainPage()
		{
			// Required to initialize variables
			InitializeComponent();
			bush.Visibility = Visibility.Collapsed;
			tree.Visibility = Visibility.Collapsed;
			rock.Visibility = Visibility.Collapsed;
			bunny1.Visibility = Visibility.Collapsed;
			bunny2.Visibility = Visibility.Collapsed;
			bunny3.Visibility = Visibility.Collapsed;
			bunny4.Visibility = Visibility.Collapsed;
			bunny5.Visibility = Visibility.Collapsed;
			bunny6.Visibility = Visibility.Collapsed;
			bunny7.Visibility = Visibility.Collapsed;
			bunny8.Visibility = Visibility.Collapsed;
            dispatcherTimer.Tick += dispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
		}

		private void button_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// TODO: Add event handler implementation here.
			bunny.Visibility = Visibility.Collapsed;
			title.Visibility = Visibility.Collapsed;
			button.Visibility = Visibility.Collapsed;
            wordBalloon.Visibility = Visibility.Collapsed;
			bush.Visibility = Visibility.Visible;
			tree.Visibility = Visibility.Visible;
            rock.Visibility = Visibility.Visible;
            Storyboard1.Begin();
            dispatcherTimer.Start();
		}

		private void bunny_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
            GameWin();		
		}

        private void bunny1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny4_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny5_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny6_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny7_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        private void bunny8_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GameWin();
        }

        public void GameWin()
        {
            Storyboard1.Stop();
            bunny.Visibility = Visibility.Visible;
            title.Visibility = Visibility.Visible;
            button.Visibility = Visibility.Visible;
            bush.Visibility = Visibility.Collapsed;
            tree.Visibility = Visibility.Collapsed;
            rock.Visibility = Visibility.Collapsed;
            title.Text = "YOU WIN!";
            button.Content = "Play again";
        }

        public void dispatcherTimer_Tick(object sender, object e)
        {
            int x = random.Next(500);
            TimeSpan time = new TimeSpan(0, 0, x);
            Storyboard1.Seek(time);
        }
	}
}